"use strict";

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

$(".showPassword").click(function () {
  $(this).hasClass("icon-yincangbukejian") ? ($(this).removeClass("icon-yincangbukejian"), $(this).addClass("icon-kejian"), $(this).prev().prop("type", "text")) : ($(this).addClass("icon-yincangbukejian"), $(this).removeClass("icon-kejian"), $(this).prev().prop("type", "password"));
});var captcha = captchaBigData("#captcha0"),
    setTime = ($("form button").click(function () {
  var e;"扫码登录" == $(this).text().replace(/\s/g, "") || $(this).hasClass("wof-button--yellow") || (e = $(this).text().replace(/\s/g, ""), e = ["账号登录", "短信登录"].indexOf(e), $("#captcha0").text(""), $("#captcha1").text(""), captcha = captchaBigData("#captcha" + e));
}), $("form .wof-button--yellow").click(function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(e) {
    var t, s;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            console.log(111), e.preventDefault();e = $(this).text().replace(/\s/g, "");_context.t0 = (console.log($(this).text()), e);
            _context.next = _context.t0 === "账号登录" ? 5 : _context.t0 === "短信登录" ? 16 : 22;
            break;

          case 5:
            t = $(".account").val(), s = $(".pwd").val();

            if (/(^\d{10}$)|^\w{5,15}$/.test(t)) {
              _context.next = 8;
              break;
            }

            return _context.abrupt("return", void $.message({ message: "账号格式有误", type: "error" }));

          case 8:
            if (/^\w{8,16}$/.test(s)) {
              _context.next = 10;
              break;
            }

            return _context.abrupt("return", void $.message({ message: "密码格式有误", type: "error" }));

          case 10:
            _context.next = 12;
            return captcha;

          case 12:
            if (_context.sent.getValidate()) {
              _context.next = 14;
              break;
            }

            return _context.abrupt("return", void $.message({ message: "请验证", type: "error" }));

          case 14:
            $.post("http://kg.zhaodashen.cn/mt/web/user/login.jsp", { account: t, pwd: s }, function (e) {
              var t;200 === e.meta.state ? (console.log(e), $.message({ message: "登录成功", type: "success" }), t = $("#remember").prop("checked"), console.log(t), t ? (localStorage.setItem("uname", e.data.uname), localStorage.setItem("token", e.data.token), localStorage.setItem("expires", new Date().getTime() + 1e4)) : (sessionStorage.setItem("uname", e.data.uname), sessionStorage.setItem("token", e.data.token)), location.href = "./index.html") : $.message({ message: "账号或者密码有误", type: "error" });
            }, "json");return _context.abrupt("break", 22);

          case 16:
            t = $(".mobile").val(), s = $(".code").val();
            if (!(!t || !s)) {
              _context.next = 19;
              break;
            }

            return _context.abrupt("return", void $.message({ message: "手机号或验证码不能为空", type: "error" }));

          case 19:
            if (!(console.log(111), !/^1\d{10}$/.test(t))) {
              _context.next = 21;
              break;
            }

            return _context.abrupt("return", void $.message({ message: "手机号有误，请重新输入", type: "error" }));

          case 21:
            $.post("http://kg.zhaodashen.cn/mt/web/sms/login.jsp", { mobile: t, code: s }, function (e) {
              201 === e.meta.state ? ($.message({ message: "登陆成功", type: "success" }), setTimeout(function () {
                location.href = "./index.html";
              }, 2e3)) : $.message({ message: e.meta.msg, type: "error" });
            }, "json");
          case 22:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function (_x) {
    return _ref.apply(this, arguments);
  };
}()), 5),
    t1 = null;$(".getNum").click(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
  var _this = this;

  var e;
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
    while (1) {
      switch (_context2.prev = _context2.next) {
        case 0:
          _context2.t0 = t1;

          if (_context2.t0) {
            _context2.next = 11;
            break;
          }

          e = $(".mobile").val();
          /^1\d{10}$/.test(e) || $.message({ message: "请输入正确的手机号", type: "error" });
          _context2.next = 6;
          return captcha;

        case 6:
          if (!_context2.sent.getValidate()) {
            _context2.next = 10;
            break;
          }

          $.message({ message: "发送成功", type: "success" }), $(this).text(setTime + "s秒后重新发送"), t1 = setInterval(function () {
            setTime--, $(_this).text(setTime + "s秒后重新发送"), setTime <= 0 && (clearInterval(t1), t1 = null, setTime = 5, $(_this).text("重新获取"));
          }, 1e3), $.post("http://kg.zhaodashen.cn/mt/web/sms/send.jsp", { mobile: e }, function (e) {
            console.log(e);
          }, "json");
          _context2.next = 11;
          break;

        case 10:
          $.message({ message: "请验证", type: "error" });

        case 11:
        case "end":
          return _context2.stop();
      }
    }
  }, _callee2, this);
})));